//
//  LJFHotCell.m
//  SevenZhou
//
//  Created by qianfeng on 15/9/16.
//  Copyright (c) 2015年 ljf. All rights reserved.
//

#import "LJFHotCell.h"
#import "Helper.h"

@implementation LJFHotCell

- (void)awakeFromNib
{
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setArray:(NSArray *)array
{
    _array = array;
    
    CGFloat maginX = 10;
    CGFloat maginY = 10;
    CGFloat Width = 0;
    
    for (int i = 0; i < array.count; i++)
    {
        if (i >= 8)
        {
            return;
        }
        
        if (i == 4)
        {
            maginX = 10;
            Width = 0;
            maginY = 55;
        }
        
        maginX = maginX + (Width) + 5;
        
        Width = [Helper widthOfString:array[i] font:[UIFont systemFontOfSize:17] height:35];
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        
        button.titleLabel.font = [UIFont systemFontOfSize:17];
        button.frame = CGRectMake(maginX , maginY, Width+20, 30);
        [button setTitle:array[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithRed:13/255.0 green:140/255.0 blue:29/255.0 alpha:1.0] forState:UIControlStateNormal];
        button.backgroundColor = [UIColor clearColor];
        button.layer.borderColor = [UIColor colorWithRed:13/255.0 green:140/255.0 blue:29/255.0 alpha:1.0].CGColor;
        button.layer.borderWidth = 2;
        button.layer.cornerRadius = 15;
        button.tag = 140 + i;
        
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:button];
        
        Width = Width + 20;

    }
}

- (void) buttonClick:(UIButton *)button
{
    NSInteger tag = button.tag;
    
    [_mydeletage LJFHotCell:self andSearchKeyStringTag:tag - 140];
}

- (void) setRecordArr:(NSArray *)recordArr
{
    _recordArr = recordArr;
    
    CGFloat maginX = 10;
    CGFloat maginY = 10;
    CGFloat Width = 0;
    
    for (int i = 0; i < recordArr.count; i++)
    {
        if (i >= 10)
        {
            return;
        }
        
        if (i == 5)
        {
            maginX = 10;
            Width = 0;
            maginY = 55;
        }
        
        maginX = maginX + (Width) + 5;
        
        Width = [Helper widthOfString:recordArr[i] font:[UIFont systemFontOfSize:17] height:35];
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        
        button.titleLabel.font = [UIFont systemFontOfSize:17];
        button.frame = CGRectMake(maginX , maginY, Width+20, 30);
        [button setTitle:recordArr[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        button.tag = 400 + i;
        [button addTarget:self action:@selector(searchClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:button];
        
        Width = Width + 20;
        
    }
}

- (void) searchClick:(UIButton *)button
{
    NSInteger tag = button.tag;
    
    [_mydeletage LJFHotCell:self andSearchRecordTag:tag - 400];
}

@end
